<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    function fn(total,size,page,btnCount) {
const arr = []

const pageNum = total/size // 算出总页数
if(pageNum>btnCount){
const res = pageNum-page // 3
if(res>=2){
for(var m=0;m<btnCount;m++){
arr[m]=page-2+m
// console.log(arr[m])
}
return arr
}else{
    for(var n=0;n<btnCount;n++){
arr[n]=page-(pageNum-res-1)+n
}
return arr
}
}else{
    // 不满足条件,直接显示所有按钮
    for(var i=0;i<pageNum;i++){
        arr[i]=i+1
    }
    return arr
}
}
console.log(fn(100,10,4,5))
</script>
</html>